<#include "document/views/baidu/header/headerAdmin.ftl">
<#--<link rel="stylesheet" href="../document/static/css/collection.css" type="text/css">-->

    <!--右边内容栏-->
    <div class="right_main">

        <form action="news" method="post" id="formNews">
            <div class="shaixuan_box">

                <span>前序关键词：</span><input type="text" name="orderKey" class="in_2"/>
                <span>关键字：</span><input type="text" name="key" class="in_2"/>
                <span>时间范围：</span>
                <select name="time">
                    <option value="0">不限</option>
                    <option value="1">一个月内</option>
                    <option value="3">三个月内</option>
                    <option value="6">六个月内</option>
                </select>
                <span>区域：</span>
                <select name="province">
                    <option value="0">全国</option>
                    <#list locationList as location>
                        <option value="${location.code}">${location.name}</option>
                    </#list>
                </select>
                <br>
                <input type="radio" name = "excelType" id="excelType0" value="0" checked >详细查询（搜索中标详细信息）
                <input type="radio" name = "excelType" id="excelType2" value="2"> 快速查询（不搜索中标详细信息）

                <input type="button" id="search_btn" onclick="submitForm();" value="查询" class="in_3"/>
                <input type="button" id="excel_btn" onclick="submitForm(1);" value="下载Excel" class="in_3"/>
                <#--<button class="in_3" style="width: 50px;"><span class="glyphicon glyphicon-envelope"></span></button>-->

                <#-- 邮件发送判断 -->
                <#--<input type="hidden" value="0" name="excelType">-->
                <input type="hidden" value="0" name="sendExcelType">
            </div>

            <div class="shaixuan_box">
                <span>邮箱地址：</span><input type="text" name="toAddress" style="width:250px; " placeholder="输入地址，将搜索结果发送致邮箱。" class="in_2"/>
                <input type="button" id="toSendEmail_but"  onclick="toSendEmail()" value="发送" class="in_3"/>
            </div>

        </form>

        <div class="table_box" style="display: block;width: 80%">
            <table class="gridtable">
                <thead>
                <tr>
                    <th style="width: 50px">ID</th>
                    <th >标题</th>
                    <th style="width: 100px">时间</th>
                    <th style="width: 250px">招标单位</th>
                    <th style="width: 150px">招标单位联系人</th>
                    <th style="width: 150px">招标单位联系电话</th>
                    <th style="width: 100px">查看采购方的关系公司</th>
                </tr>
                </thead>

                <tbody id="table_tbody_one">
                <#--<#list list as x>-->
                <#--<tr>-->
                    <#--<td>${x_index+1}</td>-->
                    <#--<td><a href="http://zb.zbmao.cn/home/snapShot?districtNewsId=${x.district_news_id}&location=${x.province_id}" target="_blank">${x.title}</a></td>-->
                    <#--<td>${x.starTime}</td>-->
                    <#--<td>${x.subscriber}</td>-->
                    <#--<td>${x.subscriber_contact}</td>-->
                    <#--<td>${x.subscriber_phone}</td>-->
                    <#--<td><input type="button" value="查看" onclick="content_1(${x_index+1},'${x.subscriber}')" class="inp_${x_index+1}"/></td>-->
                    <#--<tr class="content content_${x_index+1}" style="padding:5px">-->
                    <#--<td colspan="7" >-->
                        <#--<div style="width:100%; " class="content content_${x_index+1}">-->
                            <#--<table class="gridtable" id="table_${x_index+1}" width="100%;" style="word-break:break-all; word-wrap:break-word;background-color: #fff;"></table>-->
                         <#--</div>-->
                    <#--</td>-->
                    <#--</tr>-->
                <#--</tr>-->
                <#--</#list>-->
                </tbody>

            </table>
        </div>

        <div id="gifD" style='display: none;margin:10px auto;width: 200px;'><img src='../../static/admin/gif/ajax-loader-7.gif'></div>

        <#-- 分页 -->
        <div id="table_page_one"><ul class="y_box" ></ul></div>


    </div>


<!--footer-->
<div class="footer" style="position: fixed;left: 0px;bottom: 0px">
    <p style="color:#fff; line-height:40px; text-align:center; font-size:12px; margin:0; padding:0;">Copyright 2016 深圳数众科技有限公司. All Rights Reserved.粤ICP备15077582号</p>
</div>




<script type="text/javascript">
    var ListJson='${listJson}';
    var List=eval(ListJson);
    var Row=50;
    var MaxPage=${maxPage};
    function tablePage(nowPage){
        if(MaxPage==0)return "";

        var orderKey='${orderKey}';
        var key='${key}';
        var list=List;
        var start=(nowPage-1)*Row;
        var end=nowPage*Row;
        var html="";
        $.each(list,function(index,x){
            if(index>=start && index<end){
                var x_index=index+1;
                html+='<tr>';
                html+='<td>'+x_index+'</td>';
                html+='<td><a href="http://zb.zbmao.cn/home/snapShot?keyList='+orderKey+' '+key+'&districtNewsId='+x.district_news_id+'&location='+x.province_id+'" target="_blank">'+(heightKey(key+" "+orderKey,x.title))+'</a></td>';
                html+='<td>'+x.starTime+'</td>';
                html+='<td>'+x.subscriber+'</td>';
                html+='<td>'+x.subscriber_contact+'</td>';
                html+='<td>'+x.subscriber_phone+'</td>';
                html+='<td><input type="button" value="查看" onclick="content_1('+x_index+',\''+x.subscriber+'\')" class="inp_'+x_index+'"/></td>';
                html+='<tr class="content content_'+x_index+'" style="padding:5px">';
                html+='<td colspan="7" >';
                html+='<div style="width:100%; " class="content content_'+x_index+'">';
                html+='<table class="gridtable" id="table_'+x_index+'" width="100%;" style="word-break:break-all; word-wrap:break-word;background-color: #fff;"></table>';
                html+='</div>';
                html+='</td>';
                html+='</tr>';
                html+='</tr>';
            }
        });
        return html;
    }

    function toPaging(nowPage){
        var tableHtml=tablePage(nowPage);
        var pageHtml=table_page("toPaging",nowPage,MaxPage);

        $("#table_tbody_one").html(tableHtml);
        $("#table_page_one .y_box").html(pageHtml);
    }

    //标题高亮
    function heightKey(key,title){
        var array=key.trim().split(" ");
        var rs=title;
        var _color=["#FF6868","deepskyblue","#ffff00","green"];
        $.each(array,function(index,x){
            var n=parseInt(index % _color.length);
            rs=rs.split(x).join("<span style='color:#FFFFFF;background-color: "+_color[n]+";'>"+x+"</span>");
        });
        return rs;
    }


    /* excelType:0不下载，1下载 */
    function submitForm(excelType){
        if(excelType==1){
            /* 下载 */
            var excelUrl='${excelUrl}';
            if(excelUrl!=""){
                window.open(excelUrl);
            }

        }else{
            /* 关键词为空时跳出 */
            var keyStr=$("input[name=orderKey]").val()+$("input[name=key]").val();
            if(keyStr.trim() == ""){
                alert("关键词不能为空!");
                $("#toSendEmail_but").attr("disabled",false).css("hover","").css("background-color","#19a9eb").css("cursor","").val("发送");
                return;
            }
            $(".table_box").css("display","none");
            $("#gifD").css("display","block");
            $("#table_page_one").html("");
            $("#formNews").submit();
        }
    }

    //邮件发送
    function toSendEmail(){
        var orderKey='${orderKey}';
        var key='${key}';
        var province='${province}';
        var time = '${time}';
        var excelType='${excelType}';
        var _orderKey=$('input[name=orderKey]').val();
        var _key=$('input[name=key]').val();
        var _excelType = $('input[name=excelType]:checked').val();
        var _province=$('select[name=province] option:selected').val();
        var _time=$('select[name=time] option:selected').val();

        var bool=orderKey!=_orderKey || key!=_key || province!=_province || time!=_time || excelType!=_excelType;
        //alert(_orderKey+":"+_key+":"+_province+":"+_time+":"+(orderKey!=_orderKey)+(key!=_key)+(province!=_province)+(time!=_time)+bool);

        var email=$("input[name=toAddress]").val();
        var excelUrl='${excelUrl}';
        //alert(email+":"+excelUrl);
        if(email==""){
            alert("请先输入邮箱地址");
            return;
        }else if(excelUrl==""){
            $("input[name=sendExcelType]").val(1);
            $("#toSendEmail_but").attr("disabled",true).css("hover","").css("background-color","#ccc").css("cursor","no-drop").val("发送中...");
            submitForm(0);
            return;
        }else if(bool){
            $("input[name=sendExcelType]").val(1);
            $("#toSendEmail_but").attr("disabled",true).css("hover","").css("background-color","#ccc").css("cursor","no-drop").val("发送中...");
            submitForm(0);
            return;
        }

        $("#toSendEmail_but").attr("disabled",true).css("hover","").css("background-color","#ccc").css("cursor","no-drop").val("发送中...");
        $.post(
                "sendEmail",
                {excelUrl:excelUrl,toEmail:email},
                function(data){
                    alert(data.rs=="1"?"发送成功":"发送失败");
                    $("#toSendEmail_but").attr("disabled",false).css("hover","").css("background-color","#19a9eb").css("cursor","").val("发送");
                }
        );
        $("input[name=sendExcelType]").val(0);
    }



    $(function(){
        var orderKey='${orderKey}';
        var key='${key}';
        var province='${province}';
        var time = '${time}';
        var sendExcelType='${sendExcelType}';
        var toAddress='${toAddress}';
        var excelUrl='${excelUrl}';
        var excelType='${excelType}';
        $('input[name=orderKey]').val(orderKey);
        $('input[name=key]').val(key);

        if(excelType==0){
            $("#excelType0").attr("checked","checked");
        }else if(excelType==2){
            $("#excelType2").attr("checked","checked");
        }
        $('select[name=province]').val(province);
        $('select[name=time]').val(time);
        $('input[name=sendExcelType]').val(sendExcelType);
        if(toAddress!=""){
            $('input[name=toAddress]').val(toAddress);
        }

        /* 下载样式 */
        if(key=="" && orderKey==""){
            $("#excel_btn").attr("disabled",true).css("hover","").css("background-color","#ccc").css("cursor","no-drop");
        }

        toPaging(1);

        /* 判断是否发送邮件 */
        if(sendExcelType=="1"){
            if(excelUrl==""){
                alert("未查到数据！");
            }else{
                toSendEmail();
            }
        }

    });

    var newsMap='${newsMap}';
    var mapNews=eval("("+newsMap+")");

    var mapSuccessContact='${mapSuccessContact}';
    var successContact=eval("("+mapSuccessContact+")");

    function content_1(idText,subscriber){
        var orderKey='${orderKey}';
        var key='${key}';
        var list=mapNews[subscriber];
        if(list.length==0){
            $("#table_"+idText).html("未查询到相关数据");
            $(".content_"+idText).slideToggle();
            return;
        }
        if($("#table_"+idText).html()!=""){
            $(".content_"+idText).slideToggle();
            $("#table_"+idText).html("");
            return;
        }
        var html="<tr>";
        html+="<th width='50px'>ID</td>";
        html+="<th>中标公司</th>";
        html+="<th width='250px'>手机</th>";
        html+="<th width='250px'>固话</th>";
        html+="<th width='250px'>邮箱</th>";
        html+="<th style='width: 30px'>中标信息</th>";
        html+="</tr>";
        $.each(list,function(index,x){
            html+="<tr><td>";
            html+=index+1;
            html+="</td><td>";
            html+=x;
            html+="</td><td>";
            if(successContact[x].cellphone!=undefined) {
                html += successContact[x].cellphone;
            }
            html+="</td><td>";
            if(successContact[x].com_phone!=undefined) {
                html += successContact[x].com_phone;
            }
            html+="</td><td>";
            if(successContact[x].email!=undefined) {
                html += successContact[x].email;
            }
            html+="</td><td>";
            html+="<input type='button' value='查看' style='background-color:#71bb35;' onclick='content_2("+index+")' class='inp_"+index+"_"+index+"'/></td>";
            html+="<tr class='content content_"+index+"_"+index+"' style='padding:5px'>";
            html+="<td colspan='7' >";
            html+="<div style='width:100%;' class='content content_"+index+"_"+index+"'>";
            html+="<table class='gridtable' id='table_"+index+"_"+index+"' width='100%;' style='word-break:break-all; word-wrap:break-word;background-color: #fff;'>";
            html+="<tr>";
            html+="<th width='50px'>ID</td>";
            html+="<th>标题</th>";
//            html+="<th width='250px'>入库时间</th>";
//            html+="<th width='250px'>金额</th>";
            html+="</tr>";
            $.each(successContact[x].listNews,function(index_news,x_news){
                html+="<tr><td>";
                html+=index_news+1;
                html+="</td><td>";
                html+="<a href='http://zb.zbmao.cn/home/result_snapShot?keyList="+orderKey+" "+key+"&districtNewsId="+x_news.district_news_id+"&location="+x_news.provinceId+"' target='_blank'>";
                html+= x_news.title;
                html+="</a></td><td>";
//                html+= x_news.starTime;
//                html+="</td><td>";
//                html+= x_news.win_bid_figure;
                html+="</tr>";
            });
            html+="</table></div></td></tr>";
            html+="</tr>";
        });
        $("#table_"+idText).html(html);
        $(".content_"+idText).slideToggle();
    }
    function content_2(idText){
        $(".content_"+idText+"_"+idText).slideToggle();
    }


    /**************************************************************************************************/
    /** table_page 分页
     * methodName:跳转方法
     * page:当前页
     * maxPage：最大页
     */
    function table_page(methodName,page,maxPage){
        var html='';
        page=page-1+1;
        maxPage=maxPage-1+1;

        //上一页
        if(page==1){//<li><a href="#">上一页</a></li>
            //html+='<li><a href="javascript:;">上一页</a></li>';
        }else{
            html+='<li ><a href="javascript:'+methodName+'('+(page-1)+');">上一页</a></li>';
        }
        //首页
        /* if(page==1){
             html+='<li><a href="javascript:;">首页</a></li>';
         }else{
             html+='<li><a href="javascript:'+methodName+'(1);">首页</a></li>';
         }*/

        //数字下标页
        var p=0;
        if(maxPage-page<2){
            var z=page-(5-(maxPage-page+1));
            for(var i=(z>0?z:1);i<page;i++){
                html+='<li ><a  href="javascript:'+methodName+'('+i+');">'+i+'</a></li>';
                p++;
            }
        }else{
            for(var i=(page-2>0?page-2:1);i<page;i++){
                html+='<li ><a  href="javascript:'+methodName+'('+i+');">'+i+'</a></li>';
                p++;
            }
        }
        html+='<li ><a  href="javascript:;" style="border:none; font-weight:bold; background-color:#fff;">'+page+'</a></li>';
        p++;
        for(var j=page+1;j<=maxPage && p<5;j++){
            html+='<li ><a  href="javascript:'+methodName+'('+j+');">'+j+'</a></li>';
            p++;
        }
        //下一页
        if(page+1<=maxPage){
            html+='<li ><a  href="javascript:'+methodName+'('+(page-1+2)+');">下一页</a></li>';
        }else{
            //html+='<li ><a  href="javascript:;">下一页</a></li>';
        }

        if(maxPage<=1){
            html="";
        }

        return html;
    }

</script>
</body>
</html>
